package com.study.talk.module.netty;

import com.study.talk.common.code.MessageDecoder;
import com.study.talk.common.code.MessageEncoder;
import com.study.talk.common.code.Splitter;
import com.study.talk.module.netty.handler.*;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * 初始化配置类
 */

@Component
public class TalkServerInitializer extends ChannelInitializer<SocketChannel> {

    @Resource
    private AcceptGroupRequestHandler acceptGroupRequestHandler;

    @Resource
    private AcceptJoinGroupRequestHandler acceptJoinGroupRequestHandler;

    @Resource
    private AcceptAddUserRequestHandler acceptAddUserRequestHandler;

    @Resource
    private ApplyAddUserRequestHandler applyAddUserRequestHandler;

    @Resource
    private ApplyGroupRequestHandler applyGroupRequestHandler;

    @Resource
    private CreateGroupRequestHandler createGroupRequestHandler;

    @Resource
    private GroupMessageHandler groupMessageHandler;

    @Resource
    private HeartBeatRequestHandler heartBeatRequestHandler;

    @Resource
    private IMIdleStateHandler imIdleStateHandler;

    @Resource
    private InviteGroupRequestHandler inviteGroupRequestHandler;

    @Resource
    private LoginRequestHandler loginRequestHandler;

    @Resource
    private MessageRequestHandler messageRequestHandler;

    @Resource
    private SyncRequestHandler syncRequestHandler;

    @Resource
    private SmsSendHandler smsSendHandler;

    @Override
    protected void initChannel(SocketChannel sc) throws Exception {
        sc.pipeline().addLast(new Splitter());
        sc.pipeline().addLast(new MessageDecoder());
        sc.pipeline().addLast(imIdleStateHandler);
        sc.pipeline().addLast(acceptGroupRequestHandler);
        sc.pipeline().addLast(acceptJoinGroupRequestHandler);
        sc.pipeline().addLast(acceptAddUserRequestHandler);
        sc.pipeline().addLast(applyAddUserRequestHandler);
        sc.pipeline().addLast(applyGroupRequestHandler);
        sc.pipeline().addLast(createGroupRequestHandler);
        sc.pipeline().addLast(groupMessageHandler);
        sc.pipeline().addLast(heartBeatRequestHandler);
        sc.pipeline().addLast(inviteGroupRequestHandler);
        sc.pipeline().addLast(loginRequestHandler);
        sc.pipeline().addLast(messageRequestHandler);
        sc.pipeline().addLast(syncRequestHandler);
        sc.pipeline().addLast(smsSendHandler);
        sc.pipeline().addLast(new MessageEncoder());

    }
}
